<template>
  <c-permission-tabs>
    <el-tab-pane label="关联装修任务" name="1">
      <c-table-box hide-func no-request :data="tableData1" :table-config="tableConfig1" />
    </el-tab-pane>
    <el-tab-pane label="验收区域及系列" name="2">
      <!-- <CheckArea v-if="tableData2_0.length===0" preview :data="tableData2_1" /> -->
      <c-permission-tabs :lazy="false">
        <el-tab-pane label="本次验收区域" name="checkArea">
          <CheckArea preview :data="tableData2_1" />
        </el-tab-pane>
        <el-tab-pane label="非本次验收区域" name="noCheckArea">
          <CheckArea preview :data="tableData2_0" />
        </el-tab-pane>
      </c-permission-tabs>
    </el-tab-pane>
    <el-tab-pane label="验收问题明细" name="3">
      <c-table-box hide-func :index="false" no-request :data="tableData3" :table-config="tableConfig3">
        <el-table-column slot="before" type="expand" width="50">
          <template v-slot="{row}">
            <div style="padding:10px">
              <c-table-box :index="false" :data="row.problemDetailDTOList" hide-func :setting="false" :table-config="tableConfig6">
                <!-- <el-table-column min-width="200" label="验收问题说明">
                  <template slot-scope="scope">
                    <el-tooltip v-if="scope.row.problemDesc" effect="dark" placement="top-start">
                      <span style="min-width:200px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
                        {{ scope.row.problemDesc }}
                      </span>
                      <template #content>
                        <div style="white-space:pre-wrap">{{ scope.row.problemDesc }}</div>
                      </template>
                    </el-tooltip>
                  </template>
                </el-table-column> -->
              </c-table-box>
            </div>
          </template>
        </el-table-column>
      </c-table-box>
    </el-tab-pane>
    <el-tab-pane label="项目验收评估" name="4">
      <c-table-box hide-func no-request class="table-span" :data="tableData4" :table-span-method="spanMethod" :table-config="tableConfig4" />
    </el-tab-pane>
    <el-tab-pane label="验收附件" name="5">
      <!-- belong-model="HARD_REPORT" -->
      <c-file-table-box :model-id="$route.query.id" type-code="ACCESS027,ACCESS028,ACCESS029,ACCESS030" :editable="false" />
    </el-tab-pane>
  </c-permission-tabs>
</template>
<script>
import { getSelectByAccId, postAcceptAreaSeriesDetailPage, getProblemDetailList, postConstUnitAssessScoreDetail } from '@/api/check'
import CheckArea from '../execute/components/checkArea'
export default {
  name: 'RelevanceData',
  components: {
    CheckArea
  },
  props: {
    unitCode: {
      type: String,
      default: undefined
    },
    type: {
      type: String,
      default: undefined
    }
  },
  data() {
    return {
      tableData1: [],
      tableConfig1: {
        interfacePath: '',
        setting: [
          {
            prop: 'decorationTaskCode',
            width: 200,
            label: '装修任务号',
            className: 'btn-green',
            isButton: true,
            clickFun: this.toDetail
          },
          {
            prop: 'actualApproachTime',
            label: '装修进场时间',
            formatData: this.$parseTimeYMD('actualApproachTime')
          },
          {
            prop: 'actualEndTime',
            label: '装修完工时间',
            formatData: this.$parseTimeYMD('actualEndTime')
          },
          {
            prop: 'range',
            label: '装修范围',
            render(h, row) {
              return h('c-dict-range-view', {
                props: {
                  dictTypeCode: 'DECORATION_RANGE',
                  value: row.range
                }
              })
            }
          },
          {
            prop: 'decorationType',
            label: '装修类型',
            render: (h, row) => {
              return h('c-dict-range-view', {
                props: {
                  dictTypeCode: 'DECORATION_FORM',
                  value: row.decorationFormCal || row.decorationForm
                }
              })
            }
          },
          {
            prop: 'nature',
            label: '装修性质',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'DECORATION_NATURE'
            }
          },
          {
            prop: 'shopWholeTotalArea',
            label: '对应整装图纸总面积'
          },
          {
            prop: 'shopSimpleTotalArea',
            label: '对应简装图纸总面积'
          },
          {
            prop: 'softwearTaskCode',
            label: '对应软装陈列任务号'
          }
        ]
      },
      tableData2_1: [],
      tableData2_0: [],
      tableConfig2: {
        interfacePath: '',
        setting: [
          {
            prop: 'areaName',
            label: '所属区域'
          },
          {
            prop: 'programName',
            label: '方案名称'
          },
          {
            prop: 'actualOutpicArea',
            label: '实际出图面积'
          },
          {
            prop: 'acceptArea',
            label: '验收面积'
          },
          {
            prop: 'acceptDesc',
            label: '验收说明'
          },
          {
            prop: 'seriesName',
            label: '系列名称'
          },
          {
            prop: 'seriesOutpicArea',
            label: '实际出图面积'
          }, {
            prop: 'acceptSeriesArea',
            label: '验收面积'
          },
          {
            prop: 'acceptSeriesDesc',
            label: '验收说明'
          },
          {
            prop: 'isConstRangeAccept',
            label: '是否建设范围内验收',
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'acceptTaskCode',
            width: 200,
            label: '验收任务号'
          }
        ]
      },
      tableData3: [],
      tableConfig3: {
        interfacePath: '',
        setting: [
          {
            prop: 'belongDuty',
            label: '责任归属'
          },
          {
            prop: 'principalName',
            label: '责任人'
          },
          {
            prop: 'acceptResult',
            label: '验收结果',
            propEnum: {
              appCode: 'slm',
              domainCode: 'marketing',
              dictTypeCode: 'ACCEPT_RESULT'
            }
            // formatData: v => {
            //   return v.acceptResult === 1 ? '通过' : '不通过'
            // }
          },
          {
            prop: 'mustRectifyEndTime',
            label: '应整改完成时间',
            formatData: this.$parseTimeYMD('mustRectifyEndTime')
          },
          {
            prop: 'rectifyTaskCode',
            label: '整改任务编号'
          },
          {
            prop: 'actualRectifyEndTime',
            label: '实际整改完成时间',
            formatData: this.$parseTimeYMD('actualRectifyEndTime')
          }
        ]
      },
      tableData4: [],
      tableConfig4: {
        interfacePath: '',
        setting: [
          {
            prop: 'scoreType',
            label: '评估类别'
          },
          {
            prop: 'totalScore',
            label: '总分值'
          },
          {
            prop: 'scoreDesc',
            label: '评估说明'
          },
          {
            prop: 'detailItem',
            label: '考核明细'
          },
          {
            prop: 'grading',
            label: '评分标准'
          },
          {
            prop: 'scoreDescItem',
            label: '评分说明'
          },
          {
            prop: 'acceptGroupScore',
            label: '验收小组评分'
          },
          {
            prop: 'supervisorScore',
            label: '工程监理评分'
          },
          {
            prop: 'customerScore',
            label: '经销商评分'
          },
          {
            prop: 'actualScore',
            label: '最终平均得分'
          }
        ]
      },
      tableConfig6: {
        setting: [
          {
            prop: 'problemClass',
            label: '问题分类',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'PROBLEM_CATEGORY'
            }
          },
          {
            prop: 'haveProblem',
            label: '是否存在问题',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'slm',
              dictTypeCode: 'BOOLEANS'
            }
          },
          {
            prop: 'problemDesc',
            label: '验收问题说明',
            minWidth: 200,
            render: function(createElement, rows) {
              if (rows.problemDesc) {
                return (<div style='white-space:pre-wrap'>{rows.problemDesc }</div>
                )
              }
              return ''
            }
          },
          {
            prop: 'rectifyDesc',
            label: '整改项说明',
            minWidth: 160,
            render: function(createElement, rows) {
              if (rows.rectifyDesc) {
                return (<div style='white-space:pre-wrap'>{rows.rectifyDesc }</div>
                )
              }
              return ''
            }
          },
          {
            prop: 'rectifyResult',
            label: '整改结果'
          }
        ]
      }
    }
  },
  watch: {
    unitCode(v) {
      if (v) {
        this.getScore(v)
      }
    }
  },
  created() {
    this.getDetail()
  },
  methods: {
    // 处理评分数据
    handlerData(data) {
      const t = []
      for (const d of data) {
        const items = d.assessDetailsDtos || []
        const len = items.length
        for (let i = 0; i < len; i++) {
          const item = items[i]
          const row = {
            acceptGroupScore: d.acceptGroupScore, //	验收小组评分
            actualScore: d.actualScore, //		实际得分
            customerScore: d.customerScore, //		经销商评分
            decorationTaskCode: d.decorationTaskCode, //		装修任务号
            id: d.id, //		ID
            scoreCriteriaId: d.scoreCriteriaId, //		评分类别配置ID
            scoreDesc: d.scoreDesc, //		考核说明
            scoreNature: d.scoreNature, //		考核性质：日常考核、项目过程考核、项目验收考核
            scoreType: d.scoreType, //		考核类别
            supervisorScore: d.supervisorScore, //		工程监理评分
            totalScore: d.totalScore, //		总分值
            unitCode: d.unitCode, //		施工单位编码
            validEndTime: d.validEndTime, //		考核有效截止时间
            validStartTime: d.validStartTime, //		考核有效开始时间
            detailItem: item.detailItem, //	考核明细
            grading: item.grading, //	评分标准
            scoreDescItem: item.scoreDesc, //	评分说明
            spanRow: 0
          }
          if (i === 0) {
            row.spanRow = len
          }
          t.push(row)
        }
      }
      return t
    },
    spanMethod({ row, column, rowIndex, columnIndex }) {
      const indexs = [0, 1, 2, 3, 7, 8, 9, 10]
      if (indexs.includes(columnIndex)) {
        return {
          rowspan: row.spanRow,
          colspan: 1
        }
      }
    },
    getDetail() {
      const { id } = this.$route.query
      getSelectByAccId(id).then(res => {
        this.tableData1 = res.data
      })
      postAcceptAreaSeriesDetailPage(id).then(res => {
        this.tableData2_1 = res.data.filter(e => e.types === 1 || e.types === '1')
        this.tableData2_0 = res.data.filter(e => e.types === 0 || e.types === '0')
      })
      getProblemDetailList(id, this.type).then(res => {
        this.tableData3 = res.data
      })
    },
    // 获取评估数据
    getScore(unitCode) {
      const { taskCode } = this.$route.query
      postConstUnitAssessScoreDetail('PRO_CHECK', unitCode, taskCode).then(res => {
        this.tableData4 = this.handlerData(res.data)
      })
    },
    // 跳转到详情
    // 详情
    toDetail(row) {
      this.$router.push({ name: 'DecorateDetail', query: { id: row.id, taskCode: row.decorationTaskCode, constCode: row.constCode }})
    }
  }
}
</script>
